# coding=utf-8，Python最好3.8以上 依赖numpy和matplotlib matplotlib如果运行有问题还要装pyqt5
# 此程序演示了一个戴森球计划中打帆的半径R与打帆建筑效率（可打帆建筑面积与球面占比）S的关系，参考文章：https://tieba.baidu.com/p/8921751857
from math import pi,cos,asin,sin
import numpy as np
import matplotlib.pyplot as plt

def get_beta(alpha: float, x: float):
   return pi/2-alpha-asin(cos(alpha)/x)

def to_rad(angle:float):
    return angle/180*pi

def area_ratio(b1,b2):
    return(sin(b1)+sin(b2))*(b2-b1)/4

def area_by_distance(au: float):
     b1=get_beta(to_rad(60),au)
     b2=get_beta(to_rad(5),au)
     return area_ratio(b1,b2)

if __name__ == '__main__':
     x=np.linspace(2,400,100)
     y=np.vectorize(area_by_distance)(x)
     print(area_ratio(to_rad(30),to_rad(85)))

     plt.plot(x/200,y*100)
     plt.xlabel('R(AU)')
     plt.ylabel('s(%)')
     plt.show()
